<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>潜在客户导入</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {

            $('#myTab a').click(function (e) {
                e.preventDefault();
                $(this).tab('show');
            });

            $('input[id=uploadFile]').change(function () {
                $('#fileInput').val($(this).val());
            });
            $('#importForm').submit(function () {

                var filepath = $('#fileInput').val();

                if (filepath.length == 0) {
                    closeTip();
                    showTip("请选择文件后再导入");
                    return false;
                }

                var extStart=filepath.lastIndexOf(".");
                var ext = filepath.substring(extStart,filepath.length).toUpperCase();
                if(ext!=".XLSX"){
                    closeTip();
                    showTip("导入文件格式错误,请下载模板后重新导入");
                    return false;
                }

                var maxsize = 8*1024*1024;//8M
                var errMsg = "上传的附件文件不能超过8M！！！";
                var tipMsg = "您的浏览器暂不支持计算上传文件的大小，确保上传文件不要超过8M，建议使用最新版的FireFox、Chrome浏览器。";

                var filesize = document.getElementById("uploadFile").files[0].size;

                if(filesize==-1){
                    closeTip();
                    showTip(tipMsg);
                    return false;
                }else if(filesize>maxsize){
                    closeTip();
                    showTip(errMsg);
                    return false;
                }

            });

            // 权重验证
            jQuery.validator.addMethod("weight", function(value, element) {
                var weight = /^\d{1,2}$/g;
                return this.optional(element) || (weight.test(value) && $("#weight").val()<= $("#userWeight").val());
            }, "请输入[ 0~"+$("#userWeight").val()+" ]之间的数字");

            $("#inputForm").validate({
                focusInvalid:true,
                focusCleanup:true,
                rules: {
                    mobile: {
                        required: function() {return $("#mobile").val()==""&&$("#telephone").val()==""; }
                    },
                    telephone: {
                        required: function() {return $("#mobile").val()==""&&$("#telephone").val()==""; }
                    }
                },
                messages: {
                    mobile: {
                        required: "手机、固定电话二选一必填"
                    },
                    telephone: {
                        required: "手机、固定电话二选一必填"
                    }
                },
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });
    </script>
    <style type="text/css">
        select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
            margin-bottom: 0px;
        }
        .table .label_td_solid{
            min-width: 100px;
            width: 10%;
        }
    </style>
</head>
<body>

<ul class="nav nav-tabs" id="myTab">
    <li class="active"><a href="#import">导入客户</a></li>
    <li><a href="#add">添加客户</a></li>
</ul>

<div class="tab-content">
    <div class="tab-pane active" id="import">
        <form id="importForm" action="${ctx}/mywork/potentialCustomer/import" method="post" enctype="multipart/form-data" class="form-search" style="padding-left:100px;padding-top:50px;text-align:left;" onsubmit="loading('正在导入，请稍等...');"><br/>
            <input id="uploadFile" name="file" type="file" style="display:none"/>

            <div class="input-append">
                <input id="fileInput" class="input-large" type="text" readonly style="width:330px;" placeholder="请选择需要导入的Excel文件" />
                <a class="btn" onclick="$('input[id=uploadFile]').click();">选择文件</a>
            </div>
             <span style="padding-left: 30px;">
		        请选择需要导入的分组:
  		        <sys:treeselect id="realGroupIdImport" name="realGroupId" value="${potentialGroup.parent.id}" labelName="realGroupName" labelValue="${potentialGroup.parent.name}" title="分组" url="/mywork/potentialCustomer/potentialGroup/treeData?addDefault=true" extId="${potentialGroup.id}" cssClass="input-small" allowClear="true"/>
             </span>
            <div style="padding-left:100px;padding-top:50px;text-align:left;">
                <input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
                <a href="${ctx}/mywork/potentialCustomer/import/template" style="padding-left:30px;">下载导入模板</a>
            </div>
        </form>
    </div>

    <div class="tab-pane" id="add">
        <form:form id="inputForm" modelAttribute="customer" action="${ctx}/mywork/potentialCustomer/import/save" method="post" class="form-horizontal">
            <sys:message content="${message}"/>
            <table class="table table-striped table-bordered table-condensed">
                <tr>
                    <th colspan="4">
                        <h5>基本信息</h5>
                    </th>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        公司名称
                    </td>
                    <td style=" width: 40%;">
                        <form:input path="corporationName" htmlEscape="false" maxlength="50" class="input-medium required"/>
                    </td>
                    <td class="label_td label_td_solid">
                        权重
                    </td>
                    <td style=" width: 40%;">
                        <input type="hidden" id="userWeight" value="${userWeight}">
                        <form:input path="weight" htmlEscape="false" maxlength="2" class="input-medium required weight"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        公司域名
                    </td>
                    <td>
                        <form:input path="corporationUrl" htmlEscape="false" maxlength="50" class="input-medium required"/>
                    </td>
                    <td class="label_td label_td_solid">
                        分组
                    </td>
                    <td>
                        <sys:treeselect id="realGroupIdAdd" name="realGroupId" value="${potentialGroup.parent.id}" labelName="realGroupName" labelValue="${potentialGroup.parent.name}" title="分组" url="/mywork/potentialCustomer/potentialGroup/treeData?addDefault=true" extId="${potentialGroup.id}" cssClass="input-small" allowClear="true"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        联系人
                    </td>
                    <td>
                        <form:input path="contactorName" htmlEscape="false" maxlength="50" class="input-medium required"/>
                    </td>
                    <td class="label_td label_td_solid">
                        性别
                    </td>
                    <td>
                        <form:radiobuttons path="contactorSex" items="${fns:getDictList('sex')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        手机号
                    </td>
                    <td>
                        <form:input path="mobile" htmlEscape="false" maxlength="11" class="input-medium mobile"/>
                    </td>
                    <td class="label_td label_td_solid">
                        联系人职务
                    </td>
                    <td>
                        <form:input path="contactorPosition" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        固定电话
                    </td>
                    <td>
                        <form:input path="telephone" htmlEscape="false" maxlength="20" class="input-medium simplePhone"/>
                    </td>
                    <td class="label_td label_td_solid">
                        备用电话
                    </td>
                    <td>
                        <form:input path="backupTelephone" htmlEscape="false" maxlength="20" class="input-medium simplePhone"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        邮箱
                    </td>
                    <td>
                        <form:input path="email" htmlEscape="false" maxlength="50" class="input-medium email"/>

                    </td>
                    <td class="label_td label_td_solid">
                        客户特点
                    </td>
                    <td>
                        <sys:customerFeature id="customerFeatureId" name="customerFeatureId" withAll="false" defaultValue="" cssClass="select-medium"></sys:customerFeature>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        省市
                    </td>
                    <td>
                        <sys:region id="provinceId" name="provinceId" withAll="false" defaultValue="" cssClass="select-medium"></sys:region>
                    </td>
                    <td class="label_td label_td_solid">
                        客户类型
                    </td>
                    <td>
                        <sys:customerType id="customerTypeId" name="customerTypeId" withAll="false" defaultValue="" cssClass="select-medium"></sys:customerType>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        行业
                    </td>
                    <td>
                        <form:input path="industry" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                    <td class="label_td label_td_solid">
                        产品意向
                    </td>
                    <td>
                        <sys:productType id="targetProducts" name="targetProducts" withWu="true" withAll="false" defaultValue="WU" cssClass="select-medium" status="OPEN"></sys:productType>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        QQ
                    </td>
                    <td>
                        <form:input path="contactorQq" htmlEscape="false" maxlength="20" class="input-medium qq"/>
                    </td>
                    <td class="label_td label_td_solid">
                        微信
                    </td>
                    <td>
                        <form:input path="contactorWechat" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                </tr>
                <tr>
                    <th colspan="4">
                        <h5>补充信息</h5>
                    </th>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        公司规模
                    </td>
                    <td>
                        <form:input path="corporationScale" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                    <td class="label_td label_td_solid">
                        成立时间
                    </td>
                    <td>
                        <input id="corporationCreateDate" name="corporationCreateDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
                               value="<fmt:formatDate value="${corporationCreateDate}" pattern="yyyy-MM-dd"/>"
                               onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        法人姓名
                    </td>
                    <td>
                        <form:input path="corporationCorporateName" htmlEscape="false" maxlength="10" class="input-medium"/>
                    </td>
                    <td class="label_td label_td_solid">
                        法人性别
                    </td>
                    <td>
                        <form:radiobuttons path="corporationCorporateSex" items="${fns:getDictList('sex')}" itemLabel="label" itemValue="value" htmlEscape="false" class="input-medium"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        经营模式
                    </td>
                    <td>
                        <form:input path="corporationBusinessModel" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                    <td class="label_td label_td_solid">
                        注册资金
                    </td>
                    <td>
                        <form:input path="corporationRegisterFunds" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        传真
                    </td>
                    <td>
                        <form:input path="corporationFax" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                    <td class="label_td label_td_solid">
                        员工人数
                    </td>
                    <td>
                        <form:input path="corporationStaffNum" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        质量体系
                    </td>
                    <td>
                        <form:input path="corporationQualitySystem" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                    <td class="label_td label_td_solid">
                        企业类型
                    </td>
                    <td>
                        <form:input path="corporationEnterpriseType" htmlEscape="false" maxlength="50" class="input-medium"/>
                    </td>
                </tr>
                <tr>
                    <td class="label_td label_td_solid">
                        公司介绍
                    </td>
                    <td>
                        <form:textarea path="corporationIntroduction" htmlEscape="false" rows="2" maxlength="500" class="input-medium" cssStyle="resize: none"/>
                    </td>
                    <td class="label_td label_td_solid">
                        注册地址
                    </td>
                    <td>
                        <form:textarea path="corporationRegisterAddress" htmlEscape="false" rows="2" maxlength="100" class="input-medium" cssStyle="resize: none"/>
                    </td>
                </tr>
            </table>
            <div class="row form-actions">
                <div class="span12">
                    <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
                </div>
            </div>
        </form:form>
    </div>
</div>
</body>
</html>
